﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Axe.Collections
{
    /// <summary>
    /// Adapter for IDictionary implementation, that wraps collection and makes it read-only.
    /// </summary>
    /// <typeparam name="TKey">The dictionary key type</typeparam>
    /// <typeparam name="TValue">The holding value type</typeparam>
    public class ReadOnlyDictionaryAdapter<TKey, TValue> : IDictionary<TKey, TValue>
    {
        private readonly IDictionary<TKey, TValue> dictionaty;

        public ReadOnlyDictionaryAdapter(IDictionary<TKey, TValue> dict)
        {
            dictionaty = dict;
        }

        public bool ContainsKey(TKey key)
        {
            return dictionaty.ContainsKey(key);
        }

        public ICollection<TKey> Keys
        {
            get { return dictionaty.Keys; }
        }

        public bool TryGetValue(TKey key, out TValue value)
        {
            return dictionaty.TryGetValue(key, out value);
        }

        public ICollection<TValue> Values
        {
            get { return dictionaty.Values; }
        }

        public TValue this[TKey key]
        {
            get
            {
                return dictionaty[key];
            }
        }


        #region ICollection<KeyValuePair<TKey,TValue>> Members

        public bool Contains(KeyValuePair<TKey, TValue> item)
        {
            return dictionaty.Contains(item);
        }

        public int Count
        {
            get { return dictionaty.Count; }
        }

        public bool IsReadOnly
        {
            get { return true; }
        }
        #endregion



        void IDictionary<TKey, TValue>.Add(TKey key, TValue value)
        {
            throw new NotImplementedException();
        }

        bool IDictionary<TKey, TValue>.Remove(TKey key)
        {
            throw new NotImplementedException();
        }

        void ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey, TValue> item)
        {
            throw new NotImplementedException();
        }

        void ICollection<KeyValuePair<TKey, TValue>>.Clear()
        {
            throw new NotImplementedException();
        }

        void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
        {
            throw new NotImplementedException();
        }

        bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
        {
            throw new NotImplementedException();
        }



        #region IEnumerable<KeyValuePair<TKey,TValue>> Members

        public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
        {
            return dictionaty.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IDictionary<TKey,TValue> Members

        TValue IDictionary<TKey, TValue>.this[TKey key]
        {
            get
            {
                return dictionaty[key];
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion
    }
}
